﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using Sustainalytics.Entities.RiskRatings;

namespace Sustainalytics.ClientDW.Synchronization.SyncRiskRatingsData
{
    public class CoreRiskRatingIndicatorMapping
    {
        public static IEnumerable<CoreRiskRatingIndicator> Map(
            IList<SharedEntities.RiskRatingsResearch.CoreRiskRatingResearchProfile> riskRatingResearchProfile)
        {
            return riskRatingResearchProfile.SelectMany(MapIndicators);
        }

        private static IList<CoreRiskRatingIndicator> MapIndicators(SharedEntities.RiskRatingsResearch.CoreRiskRatingResearchProfile profile)
        {
            var indicators = profile.Indicators.Select(Mapper.Map<CoreRiskRatingIndicator>).ToList();

            Parallel.ForEach(indicators, ind =>
            {
                ind.CompanyId = profile.Id;
            });

            return indicators;
        }
    }
}
